﻿using MvcBoost;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace System.Web.Mvc.Html
{
    public static class HtmlHelperInputExtensions
    {


        //    public static MvcHtmlString Button<TModel>(this HtmlHelper<TModel> html, string value, object htmlAttributes)
        //    {
        //        TagBuilder button = new TagBuilder("button");
        //        button.Attributes.Add("type", "button");
        //        button.Attributes.Add("value", value);

        //        var attrDict = MvcTools.Extend(htmlAttributes);
        //        button.MergeAttributes(attrDict, true);

        //        StringBuilder sb = new StringBuilder();
        //        sb.Append(button.ToString(TagRenderMode.StartTag));
        //        sb.Append(button.ToString(TagRenderMode.EndTag));
        //        return MvcHtmlString.Create(sb.ToString());
        //    }

        //    public static MvcHtmlString Button<TModel>(this HtmlHelper<TModel> html, string value)
        //    {
        //        return Button(html, value, null);
        //    }


        #region HTML Submit Rendering
        public static MvcHtmlString Submit<TModel>(this HtmlHelper<TModel> helper)
        {
            return Submit<TModel>(helper: helper, value: null);
        }

        public static MvcHtmlString Submit<TModel>(this HtmlHelper<TModel> helper, object value)
        {
            return Submit<TModel>(helper: helper, value: value, htmlAttributes: null);
        }

        public static MvcHtmlString Submit<TModel>(this HtmlHelper<TModel> helper, object value, object htmlAttributes)
        {
            var attrs = MvcTools.Extend(new { @Type = "submit", @Value = value }, htmlAttributes);
            return HtmlHelperTagExtensions.Tag<TModel>(helper: helper, tagName: "input", className: null, htmlAttributes: attrs);
        }
        #endregion

        #region HTML Button Rendering

        public static MvcHtmlString Button<TModel>(this HtmlHelper<TModel> helper)
        {
            return Button<TModel>(helper: helper, value: null);
        }

        public static MvcHtmlString Button<TModel>(this HtmlHelper<TModel> helper, object value)
        {
            return Button<TModel>(helper: helper, value: value, innerText: value);
        }


        public static MvcHtmlString Button<TModel>(this HtmlHelper<TModel> helper, object value, object innerText)
        {
            return Button<TModel>(helper: helper, value: value, innerText: innerText, htmlAttributes: null);
        }

        public static MvcHtmlString Button<TModel>(this HtmlHelper<TModel> helper, object value, object innerText, object htmlAttributes)
        {
            var attrs = MvcTools.Extend(new { @Type = "button", @Value = value }, htmlAttributes);
            return HtmlHelperTagExtensions.Tag<TModel>(helper: helper, tagName: "input", className: null, htmlAttributes: attrs,innerText: innerText);
        }
        #endregion

    }
}
